import torch
from sklearn.metrics import f1_score, recall_score

def f1_copute(dataloader,model,device):
    all_preds = []
    all_labels = []
    for (rgb_images, depth_images,shuju), labels in dataloader:
        rgb_images=rgb_images.to(device)
        depth_images = depth_images.to(device)
        shuju = shuju.to(device)
        labels = labels.to(device)

        outputs = model(rgb_images, depth_images,shuju)
        _, preds = torch.max(outputs, 1)
        all_preds.extend(preds.cpu().tolist())
        all_labels.extend(labels.cpu().tolist())
    f1 = f1_score(all_labels, all_preds, average='weighted')
    recall = f1_score(all_labels, all_preds, average='weighted')
    return f1,recall